package lab02.Test24;

import java.util.Calendar;
import java.util.Scanner;

/**
 * Created by 123 on 2017/11/1.
 */
public class Test24 {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
        Calendar cal2 = Calendar.getInstance();

        Scanner sc = new Scanner(System.in);//从键盘输入日期

        System.out.println("输两个日期如20171101");

        String day1 = new String();
        day1 = sc.nextLine();

        String day2 = new String();
        day2 = sc.nextLine();

        int Y1 = Integer.parseInt(day1.substring(0, 4));//将字符串选取适当的转换为Int型
        int M1 = Integer.parseInt(day1.substring(4, 6));
        int D1 = Integer.parseInt(day1.substring(6, 8));
        cal.set(Y1, M1, D1);//再转换为日期型
        int orlderNumber1 = cal.get(Calendar.DAY_OF_YEAR);//获得是一年中第多少天

        int Y2 = Integer.parseInt(day2.substring(0, 4));
        int M2 = Integer.parseInt(day2.substring(4, 6));
        int D2 = Integer.parseInt(day2.substring(6, 8));
        cal2.set(Y2, M2, D2);
        int orlderNumber2 = cal2.get(Calendar.DAY_OF_YEAR);//获得是一年中第多少天


        if (orlderNumber1 > orlderNumber2) {
            System.out.println("两天相差" + (orlderNumber1 - orlderNumber2));
        } else if (orlderNumber1 < orlderNumber2) {
            System.out.println("两天相差" + (orlderNumber2 - orlderNumber1));
        } else {
            System.out.println("两天相差为0");
        }

    }
}
